/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ws.jdbc.concurrent.driver.sqlserver.tds.datatypes;

/**
 * Represents a data type that has a length value associated with the data type,
 * because the data value is represented by a variable number of bytes.
 *
 * <p>
 * <a href="http://msdn.microsoft.com/en-us/library/dd358341">Reference</a>
 * </p>
 * 
 * @author Wilson Santos, 36228 <wilson.santos@ua.pt>
 */
public class VARLENTYPE {

  /** Integer. */
  public static final byte INTTYPE = 0x26;
  /** Float (15-digit precision). */
  public static final byte FLTNTYPE = 0x6D;
  /** Datetime. */
  public static final byte DATETIMNTYPE = 0x6F;
  /** VarBinary. */
  public static final byte BIGVARBINTYPE = (byte) 0xA5;
  /** VarChar. */
  public static final byte BIGVARCHRTYPE = (byte) 0xA7;
  /** NVarChar. */
  public static final byte NVARCHARTYPE = (byte) 0xE7;

        
  /**
   * Check if a given byte represents a VARLENTYPE data type.
   *
   * @param type byte to check.
   *
   * @return {@code true} if {@code type} is a VARLENTYPE data type,
   * otherwise {@code false}.
   */
  public static boolean isVarlenType(byte type) {
    return (type == INTTYPE) || (type == FLTNTYPE) || (type == DATETIMNTYPE)
            || (type == BIGVARBINTYPE) || (type == BIGVARCHRTYPE) || (type == NVARCHARTYPE);
  }

  /**
   * Check if a given VARLENTYPE data type has collation bytes.
   *
   * @param type byte to check.
   *
   * @return {@code true} if {@code type} is a VARLENTYPE data type that has
   * collation bytes, otherwise {@code false}.
   */
  public static boolean hasCollation(byte type) {
    return (type == BIGVARCHRTYPE) || (type == NVARCHARTYPE);
  }
}
